<?php

namespace SC\Qiniu\Console;

use Illuminate\Console\Command;

use Illuminate\Filesystem\Filesystem;


class InstallCommand extends Command
{
    protected $signature = 'qiniu:install';
    protected $description = 'Install qiniu CLI config';

    protected $fs = null;

    function __construct(Filesystem $fs)
    {
        parent::__construct();
        $this->fs = $fs;
    }

    function handle()
    {
        $from = static::stub_path('qiniu.php.stub');
        $to = config_path('qiniu.php');
        if (file_exists($to)) {
            $this->warn("config file ${to} already exists");
        } else {
            $this->info("copy ${from} => ${to}");
            $this->fs->copy($from, $to);
        }

        print_r("Copy following config to .env file:
QN_ACCESS_KEY=
QN_SECRET_KEY=
QN_BUCKET=
QN_HOST=
        ");
    }

    static function stub_path($path)
    {
        return realpath(__DIR__ . '/../../resources/stubs') . '/' . $path;
    }
}